package cn.iocoder.yudao.module.search.framework.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.time.Duration;

/**
 * 搜索引擎配置属性
 *
 * @author 芋道源码
 */
@ConfigurationProperties(prefix = "yudao.search")
@Validated
@Data
public class SearchProperties {

    /**
     * 搜索引擎类型
     */
    @NotBlank(message = "搜索引擎类型不能为空")
    private String type = "zincsearch";

    /**
     * 是否启用搜索功能
     */
    private Boolean enabled = true;

    /**
     * ZincSearch 配置
     */
    private ZincSearchConfig zincsearch = new ZincSearchConfig();

    /**
     * Elasticsearch 配置
     */
    private ElasticsearchConfig elasticsearch = new ElasticsearchConfig();

    /**
     * OpenSearch 配置
     */
    private OpenSearchConfig opensearch = new OpenSearchConfig();

    /**
     * MeiliSearch 配置
     */
    private MeiliSearchConfig meilisearch = new MeiliSearchConfig();

    @Data
    public static class ZincSearchConfig {
        /**
         * 服务地址
         */
        @NotBlank(message = "ZincSearch服务地址不能为空")
        private String url = "http://localhost:4080";

        /**
         * 用户名
         */
        @NotBlank(message = "ZincSearch用户名不能为空")
        private String username = "admin";

        /**
         * 密码
         */
        @NotBlank(message = "ZincSearch密码不能为空")
        private String password = "admin";

        /**
         * 连接超时时间
         */
        private Duration connectTimeout = Duration.ofSeconds(5);

        /**
         * 读取超时时间
         */
        private Duration readTimeout = Duration.ofSeconds(30);
    }

    @Data
    public static class ElasticsearchConfig {
        /**
         * 服务地址
         */
        private String url = "http://localhost:9200";

        /**
         * 用户名
         */
        private String username;

        /**
         * 密码
         */
        private String password;

        /**
         * 连接超时时间
         */
        private Duration connectTimeout = Duration.ofSeconds(5);

        /**
         * 读取超时时间
         */
        private Duration readTimeout = Duration.ofSeconds(30);
    }

    @Data
    public static class OpenSearchConfig {
        /**
         * 服务地址
         */
        private String url = "http://localhost:9200";

        /**
         * 用户名
         */
        private String username;

        /**
         * 密码
         */
        private String password;

        /**
         * 连接超时时间
         */
        private Duration connectTimeout = Duration.ofSeconds(5);

        /**
         * 读取超时时间
         */
        private Duration readTimeout = Duration.ofSeconds(30);
    }

    @Data
    public static class MeiliSearchConfig {
        /**
         * 服务地址
         */
        private String url = "http://localhost:7700";

        /**
         * API Key
         */
        private String apiKey;

        /**
         * 连接超时时间
         */
        private Duration connectTimeout = Duration.ofSeconds(5);

        /**
         * 读取超时时间
         */
        private Duration readTimeout = Duration.ofSeconds(30);
    }

}
